package api

import (
	"api_getway/basic/config"
	__ "api_getway/basic/proto"
	"api_getway/handler/request"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func AddVideo(c *gin.Context) {
	var req request.AddVideoReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	add, err := config.VideoClient.AddVideo(c, &__.AddVideoReq{
		Title:        req.Title,
		AuthorId:     req.AuthorId,
		CoverUrl:     req.CoverUrl,
		Likes:        req.Likes,
		CollectCount: req.CollectCount,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "视频发布成功",
		"id":   add.VideoId,
	})
}
